define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'deliverystaff/index' + location.search,
                    add_url: 'deliverystaff/add',
                    //edit_url: 'deliverystaff/edit',
                    del_url: 'deliverystaff/del',
                    multi_url: 'deliverystaff/multi',
                    import_url: 'deliverystaff/import',
                    dragsort_url:'',
                    table: 'delivery_staff',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'realname', title: __('Realname'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'identity_card_front_img', title: __('Identity_card_front_img'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'identity_card_reverse_img', title: __('Identity_card_reverse_img'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {0: __('待审核'), 1: __('审核通过'), 2: __('审核拒绝')}},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [

                                {
                                    name: 'audit',
                                    text: __('审核通过'),
                                    confirm:'确认审核通过吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'deliverystaff/pass',
                                    visible:function(row){
                                        if(row.status == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('审核拒绝'),
                                    confirm:'确认审核拒绝吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-danger btn-xs btn-detail  btn-ajax',
                                    url: 'deliverystaff/refuse',
                                    visible:function(row){
                                        if(row.status == 0){
                                            return true;
                                        }
                                    }
                                },

                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
